home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Magazine / SoundLab / Studio16add / sources / Float2Int.asm < prev    next >
Encoding:
Assembly Source File  |  1997-12-10  |  5.3 KB  |  250 lines

  1. *>b:Float2Int
  2.  
  3.     *«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*
  4.     *   Copyright © 1997 by Kenneth "Kenny" Nilsen.  E-Mail: kenny@bgnett.no              *
  5.     *   Source viewed in 800x600 with mallx.font (11) in CED                      *
  6.     *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  7.     *
  8.     *   Name
  9.     *    Float 2 Integer (double and single)
  10.     *
  11.     *   Function
  12.     *    converts a double to integer pluss decimal
  13.     *
  14.     *   Inputs
  15.     *    <hi float 1> <lo float 2>
  16.     *
  17.     *   Notes
  18.     *    
  19.     *   Bugs
  20.     *    
  21.     *   Created    : 01.12.97
  22.     *   Changes    : 
  23.     *««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*
  24.  
  25.  
  26. ;StartSkip    SET    1
  27. ;DODUMP        SET    1
  28.  
  29. CheckCPU    set    1
  30. Processor    =    68020
  31.  
  32.         Incdir    inc:
  33.  
  34.         include    lvo/exec_lib.i
  35.         include    lvo/dos_lib.i
  36.         include    lvo/mathieeedoubbas_lib.i
  37.         include    lvo/mathieeesingbas_lib.i
  38.  
  39.         include    digital.macs
  40.         include    digital.i
  41.  
  42.         include    dos/dos.i
  43.         include    exec/types.i
  44.  
  45.         include    startup.asm
  46.  
  47.         Incdir    ""
  48.  
  49.         dc.b    "$VER: DFloat2Int 1.1 (01.12.97)",10
  50.         dc.b    "Copyright © 1997 Digital Surface. All rights reserved. ",0
  51.         even
  52. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  53. Dump    macro
  54. Error\1    move.l    #Err\1,d1
  55.     bra    Print
  56.     endm
  57. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  58. Init        DefLib    dos,37
  59.         DefLib    mathieeedoubbas,37
  60.         DefLib    mathieeesingbas,37
  61.         DefEnd
  62.  
  63. Start    NextArg
  64.     beq    About
  65.     move.l    d0,a0
  66.     bsr    CalcArg
  67.     move.l    d0,Float1
  68.  
  69.     NextArg
  70.     beq    .single
  71.     move.l    d0,a0
  72.     bsr    CalcArg
  73.     move.l    d0,Float2
  74.  
  75.     bsr    DoubleF
  76.     bra    .done
  77.  
  78. .single    bsr    SingleF
  79.  
  80. .done    LibBase    exec
  81.     lea    String(pc),a0
  82.     lea    IntExp(pc),a1
  83.     lea    Proc(pc),a2
  84.     lea    Buff(pc),a3
  85.     Call    RawDoFmt
  86.  
  87.     LibBase    dos
  88.     move.l    #Buff,d1
  89.     Call    PutStr
  90. *------------------------------------------------------------------------------------------------------------*
  91. Close    Return    0
  92. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  93. DoubleF    LibBase    mathieeedoubbas
  94.  
  95.     move.l    Float1(pc),d0
  96.     move.l    Float2(pc),d1
  97.  
  98.     Call    IEEEDPFloor
  99.  
  100.     move.l    d0,d2
  101.     move.l    d1,d3
  102.  
  103.     Call    IEEEDPFix        ;convert number to integer
  104.     move.l    d0,IntExp        ;store
  105.  
  106.     move.l    Float1(pc),d0        ;get original number again
  107.     move.l    Float2(pc),d1
  108.     Call    IEEEDPSub        ;subtract no dec. number from original number
  109.  
  110.     move.l    d0,d6            ;=decimal only
  111.     move.l    d1,d7
  112.  
  113.     move.l    #10000,d0
  114.     Call    IEEEDPFlt        ;convert to float = max number of decimal (4)
  115.  
  116.     move.l    d6,d2            ;get decimal
  117.     move.l    d7,d3
  118.     Call    IEEEDPMul        ;multiply
  119.  
  120.     Call    IEEEDPFix        ;convert to integer
  121.     move.l    d0,IntMan        ;decimal as integer
  122.  
  123.     rts
  124. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  125. SingleF    LibBase    mathieeesingbas
  126.  
  127.     move.l    Float1(pc),d0
  128.  
  129.     Call    IEEESPFix        ;convert number to integer
  130.     move.l    d0,IntExp        ;store
  131.     Call    IEEESPFlt        ;convert back to float wo/Float2
  132.     move.l    d0,d1            ;move as substrator
  133.     move.l    Float1(pc),d0        ;get original number again
  134.     Call    IEEESPSub        ;subtract no dec. number from original number
  135.  
  136.     move.l    d0,d6            ;=decimal only
  137.  
  138.     move.l    #10000,d0
  139.     Call    IEEESPFlt        ;convert to float = max number of decimal (4)
  140.  
  141.     move.l    d6,d1            ;get decimal
  142.     Call    IEEESPMul        ;multiply
  143.  
  144.     Call    IEEESPFix        ;convert to integer
  145.     move.l    d0,IntMan        ;decimal as integer
  146.  
  147.     rts
  148. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  149. CalcArg    StackOn                ;CalcArg(string) (a0)
  150.  
  151.     lea    (a0),a5
  152.  
  153.     cmp.b    #'$',(a0)        ;only have to parse thrue the
  154.     beq.b    CalcHex            ;arg.list 'till we find no more.
  155.  
  156. CalcDec    bsr.w    ArgLen
  157.     move.l    d0,d7
  158.     beq.w    PErrS
  159.     moveq    #0,d0
  160.     moveq    #0,d1
  161.     subq    #1,d7
  162.     lea    (a5),a0
  163. .CDec    mulu    #10,d1
  164.     move.b    (a0)+,d0
  165.     cmp.b    #'0',d0
  166.     blo.w    PErrS
  167.     cmp.b    #'9',d0
  168.     bgt.w    PErrS
  169.     sub.w    #48,d0
  170.     add.w    d0,d1
  171.     dbra    d7,.CDec
  172.     bra.b    Value
  173.  
  174. CalcHex    lea    1(a0),a0        ;recalculate hex-asc value num
  175.     bsr.w    ArgLen
  176.     move.l    d0,d7
  177.     beq.w    PErrS
  178.     moveq    #0,d0
  179.     moveq    #0,d1
  180.     subq    #1,d7
  181.     lea    1(a5),a0
  182. .CHex    rol.l    #4,d1
  183.     move.b    (a0)+,d0
  184.     cmp.b    #'0',d0
  185.     blo.w    PErrS
  186.     cmp.b    #'9',d0
  187.     bgt.w    .chHex
  188. .chOk    sub.w    #48,d0
  189.     add.w    d0,d1
  190.     dbra    d7,.CHex
  191.     bra.b    Value
  192. .chHex    cmp.b    #'a',d0
  193.     blo.w    .Big
  194.     cmp.b    #'f',d0
  195.     bgt.w    PErrS
  196.     sub.l    #39,d0
  197.     bra.b    .small
  198. .Big    cmp.b    #'A',d0
  199.     blo.w    PErrS
  200.     cmp.b    #'F',d0
  201.     bgt.w    PErrS
  202.     subq    #7,d0
  203. .small    bra.b    .chOk
  204.  
  205. Value    move.l    d1,d0            ;copy value
  206.  
  207. .ok    StackOff
  208.     rts
  209.  
  210. PErrS    moveq    #0,d0
  211.  
  212.     StackOff
  213.     rts
  214.  
  215. ArgLen    move.l    a0,-(sp)
  216.     moveq    #0,d0
  217. .loop    move.b    (a0)+,d1
  218.     beq.b    .end
  219.     cmp.b    #32,d1
  220.     beq.b    .end
  221.     cmp.b    #10,d1
  222.     beq.b    .end
  223.     addq.w    #1,d0
  224.     bra.b    .loop
  225. .end    move.l    (sp)+,a0
  226.     rts
  227. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  228. Proc    move.b    d0,(a3)+
  229.     rts
  230.  
  231. About    move.l    #AboutTxt,d1
  232.  
  233. Print    LibBase    dos
  234.     Call    PutStr
  235.     bra    Close
  236. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  237. Float1        dc.l    0
  238. Float2        dc.l    0
  239.  
  240. IntExp        dc.l    0
  241. IntMan        dc.l    0
  242.  
  243. Buff        dcb.b    80,0
  244. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  245. String        dc.b    "%ld.%04.lu",10,0
  246. AboutTxt    dc.b    10,"Float2Int 1.0 by Kenneth 'Kenny' Nilsen (kenny@bgnett.no)",10,"USAGE: <hifloat> [<lofloat>]",10
  247.         dc.b    "Both = DOUBLE",10
  248.         dc.b    "One  = FLOAT",10,10,0
  249. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  250.